//
//  CustomDropButton.m
//  wtshoppingcite
//
//  Created by BaoJia-MacBookPro on 15/1/31.
//  Copyright (c) 2015年 TW. All rights reserved.
//

#import "CustomDropButton.h"

@implementation CustomDropButton


- (id)initWithFrame:(CGRect)frame type:(CUSTOMDROP_VIEW_TAG)type
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        UIImage *image = [UIImage imageNamed:@"kuang"];
//        UIImage* image = [UIImage createImageWithBgColor:MAIN_BLUE_COLOR size:CGSizeMake(160, 50) cornerRadius:3];
        [self setBackgroundImage:image forState:UIControlStateNormal];
        [self addTarget:self action:@selector(doBindPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self setTitleColor:MAIN_GRAY_COLOR forState:UIControlStateNormal];
        [self.titleLabel setFont:[UIFont systemFontOfSize:14]];
        self.contentEdgeInsets = UIEdgeInsetsMake(2,0, 0, 35);
    }
    return self;
}

- (void)setDropdownMenuViewWithData:(NSArray *)dt frame:(CGRect)frame inView:(UIView*)view{
    
    _dataSource = dt;
    _dorpViewFrame = frame;
    _muneView = view;
}


-(void)doBindPressed:(UIButton*)button{
    
    CustomDropdownMenuView * dropdownMenuView = [[CustomDropdownMenuView alloc] initWithContentSize:_dorpViewFrame.size type:DROP_DOWN_MENU_VIEW_TYPE_DEFAULT];
    [dropdownMenuView setMenuData:_dataSource];
    dropdownMenuView.delegate = self;
    [dropdownMenuView openSubMenuWithPostion:_dorpViewFrame.origin];
    [_muneView addSubview:dropdownMenuView];

}

#pragma mark CustomDropdownMenuViewDelegate
- (void)cellViewSelected:(CustomDropdownMenuView *)view data:(NSDictionary *)data
{
    NSString * title = [data objectForKey:@"name"];
    [self setTitle:title forState:UIControlStateNormal];
    
}

@end
